#include "plotcurveviewitem.h"
#include "plotview.h"
#include <QDebug>

PlotCurveViewItem::PlotCurveViewItem(std::string curName, Qt::GlobalColor color, QWidget *parent):
        QWidget(parent),
        m_curName(curName)
{
    m_form.setupUi(this);
	m_form.checkBox->setCheckState(Qt::Checked);
	QObject::connect(m_form.checkBox, SIGNAL(stateChanged(int)), this, SLOT(CheckHandle(int)));

    m_form.label->setText(QString(curName.c_str()));
	setButtonColor(m_form.pushButton, color);
}

std::string PlotCurveViewItem::getCurveName()
{
	return m_curName;
}

void PlotCurveViewItem::CheckHandle(int state)
{
    bool isOn = false;
    if(state == Qt::Checked){
        isOn = true;
    }
    emit checkStateChanged(m_curName, isOn);
}

void PlotCurveViewItem::SetLastValue(double value)
{
    m_lastValue = value;
    m_form.label_2->setText(QString::number(value));
}

void PlotCurveViewItem::setButtonColor(QPushButton *button, Qt::GlobalColor color)
{
	QColor co(color);
	QString style = "background-color: ";
	style += co.name();
	style += ";";
	button->setStyleSheet(style);
}
